package com.egao.oa.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.damon.utils.Utils;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.oa.mapper.GzhMessageMapper;
import com.egao.oa.entity.GzhMessage;
import com.egao.oa.service.GzhMessageService;
import org.springframework.stereotype.Service;
import com.egao.oa.biz.GzhMessageBiz;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 公告服务实现类
 * @author : Doman
 * @date : 2021-01-22 15:17:17
 * @version ：1.0
 */
@Service
public class GzhMessageServiceImpl /*extends ServiceImpl<GzhMessageMapper, GzhMessage> */implements GzhMessageService {

	@Autowired
	private GzhMessageBiz gzhMessageBiz;

    /**
    @Override
    public PageResult<GzhMessage> listPage(PageParam<GzhMessage> page) {
        List<GzhMessage> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<GzhMessage> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, GzhMessage gzhMessage, User loginUser)  throws Exception{
        return gzhMessageBiz.list(page,gzhMessage,loginUser);
    }

    @Override
    public List<GzhMessage> list(GzhMessage gzhMessage, User loginUser) {
        return gzhMessageBiz.list(gzhMessage,loginUser);
    }

    @Override
    public JsonResult listLast(GzhMessage gzhMessage) {
        List<GzhMessage> list = gzhMessageBiz.list(gzhMessage,new User());
        gzhMessage = null;
        if (Utils.isNotEmpty(list)) {
            gzhMessage = list.get(0);
        }
        return JsonResult.ok().setData(gzhMessage);
    }

    @Override
    public JsonResult getById(GzhMessage gzhMessage) {
        return JsonResult.ok().setData(gzhMessageBiz.getById(gzhMessage));
    }

    @Override
    public JsonResult getLast(GzhMessage gzhMessage) {
        return JsonResult.ok().setData(gzhMessageBiz.getLast(gzhMessage));
    }

    @Transactional
    @Override
    public JsonResult save(GzhMessage gzhMessage, User loginUser) {
        if (gzhMessageBiz.save(gzhMessage, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(GzhMessage gzhMessage, User loginUser) {
        if (gzhMessageBiz.update(gzhMessage, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(GzhMessage gzhMessage, User loginUser) {
        if (gzhMessageBiz.remove(gzhMessage, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
